import { renderWithQiankun, qiankunWindow, QiankunProps } from 'vite-plugin-qiankun/dist/helper';
import { createApp } from 'vue';
import router from './router';
import App from './App.vue'

import './style.css';

let app:any = null;
const render = (props: any) => {
  const { container } = props;
  app = createApp(App);
  app.use(router);
  app.mount(container ? container.querySelector('#app') : '#app');
}

renderWithQiankun({
  mount: (props) => {
    render(props);
  },
  bootstrap: () => {
    console.log('bootstrap');
  },
  unmount: (props: QiankunProps) => {
    app.unmount();
    app._container.innerHTML = '';
    app = null;
  },
  update: (props: QiankunProps): void | Promise<void> => {
    console.log('update', props);
  }
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
